package com.dao.auth;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.common.base.BaseSqlMapDAO;
import com.model.auth.SResources;

public class ResDao extends BaseSqlMapDAO{

	
	/**
	 * 
	 * @param id
	 * @param status
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<SResources> getResByParentId(Integer id,Integer status) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", id);
		map.put("status", status);
		return this.getSqlMapClientTemplate().queryForList("mresource.getResByParentId",map);
	}

	
	
	@SuppressWarnings("unchecked")
	public List<SResources> getResPageInfo(int parentId,int pageNO,int pageSize) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("parentId", parentId);
		map.put("offset", (pageNO-1)<0?0:(pageNO-1)*pageSize);
		map.put("max", pageSize);
		return this.getSqlMapClientTemplate().queryForList("mresource.getResPageInfo", map);
	}
	

	public int getResConunt(int parentId)throws Exception{
		
		return Integer.valueOf(this.getSqlMapClientTemplate().queryForObject("mresource.getResConunt",parentId).toString());
	}
	
	
	public SResources getResById(int id) throws Exception{
		
		
		return (SResources) this.getSqlMapClientTemplate().queryForObject("mresource.getResById",id);
	}
	
	public boolean delResById(int id) throws Exception{
		
		return this.getSqlMapClientTemplate().delete("mresource.delResById",id)>0;
	}
	
	
	public boolean insertRes(SResources resources) throws Exception{
		
		
		return this.getSqlMapClientTemplate().insert("mresource.insertRes", resources)!=null;
	}
	
	
	public boolean updateRes(SResources resources) throws Exception{
		
		
		return this.getSqlMapClientTemplate().update("mresource.updateRes", resources)>0;
	}
	
	/**
	 * 查询所有的栏目树
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<SResources> getAllMenus() throws Exception{
		
		return this.getSqlMapClientTemplate().queryForList("mresource.getAllMenus");
	}
}
